cmake_minimum_required(VERSION 3.20)

project(
  DBManager
  LANGUAGES CXX
  VERSION 0.1.0)

file(
  GLOB_RECURSE
  _src
  CONFIGURE_DEPENDS
  "Common/*.cpp"
  "Database/*.cpp"
  "Repository/HDF5/Base/*.cpp"
  "Repository/HDF5/Input/Node/*.cpp"
  "Repository/HDF5/Input/Property/*.cpp"
  "Repository/HDF5/Input/Subcase/*.cpp"
  "Repository/HDF5/Input/Element/*.cpp"
  "Repository/HDF5/Input/Dynamic/*.cpp"
  "Repository/HDF5/Input/Constraint/*.cpp"
  "Repository/HDF5/Input/Design/*.cpp"
  "Repository/HDF5/Input/Load/*.cpp"
  "Repository/HDF5/Input/Coordinate/*.cpp"
  "Repository/HDF5/Input/Material/*.cpp"
  "Repository/HDF5/Input/Parameter/*.cpp"
  "Repository/HDF5/Input/Partition/*.cpp"
  "Repository/HDF5/Input/Table/*.cpp"
  "Repository/HDF5/Result/ResultDomainsRepository.cpp"
  "Repository/HDF5/Result/StiffnessMatrix/*.cpp"
  "Repository/HDF5/Result/ElementalForce/*.cpp"
  "Repository/HDF5/Result/ElementalStress/*.cpp"
  "Repository/HDF5/Result/ElementalStrain/*.cpp"
  "Repository/HDF5/Result/IntegStress/*.cpp"
  "Repository/HDF5/Result/Nodal/*.cpp"
  "Repository/HDF5/Result/Summary/*.cpp"
  "Repository/HDF5/Result/Random/*.cpp"
  "Service/Input/Node/*.cpp"
  "Service/Input/Property/*.cpp"
  "Service/Input/Subcase/*.cpp"
  "IService/Input/Element/*.cpp"
  "Service/Input/Element/*.cpp"
  "Service/Input/Dynamic/*.cpp"
  "Service/Input/Constraint/*.cpp"
  "Service/Input/Design/*.cpp"
  "Service/Input/Load/*.cpp"
  "Service/Input/Coordinate/*.cpp"
  "Service/Input/Material/*.cpp"
  "Service/Input/Parameter/*.cpp"
  "Service/Input/Partition/*.cpp"
  "Service/Input/Table/*.cpp"
  "Service/Result/ResultDomainsService.cpp"
  "Service/Result/StiffnessMatrix/*.cpp"
  "Service/Result/ElementalForce/*.cpp"
  "Service/Result/ElementalStress/*.cpp"
  "Service/Result/ElementalStrain/*.cpp"
  "Service/Result/IntegStress/*.cpp"
  "Service/Result/Nodal/*.cpp"
  "Service/Result/Random/*.cpp"
  "Service/Result/Summary/*.cpp")

add_library(${PROJECT_NAME} SHARED ${_src} "DBServiceFactory.cpp" "DBAPI.cpp")

# 项目宏定义
target_compile_definitions(${PROJECT_NAME} PRIVATE EXPORTING_DBManager)

# 链接库
target_link_libraries(${PROJECT_NAME} PRIVATE DataStructure Logging Exception
                                              Stacktrace Configuration Algebra)

# 导入第三方库
import_highfive()

find_package(Boost REQUIRED CONFIG COMPONENTS filesystem)
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})

# 安装设置
install(
  TARGETS ${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION bin)

install(
  DIRECTORY IService
  DESTINATION include/DBManager
  FILES_MATCHING
  PATTERN "*.h")

install(
  DIRECTORY Common
  DESTINATION include/DBManager
  FILES_MATCHING
  PATTERN "*.h"
  PATTERN "Macro.h" EXCLUDE)

install(
  DIRECTORY Database
  DESTINATION include/DBManager
  FILES_MATCHING
  PATTERN "*.h"
  PATTERN "HDF5Database.h" EXCLUDE)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/DBServiceFactory.h
        DESTINATION include/DBManager)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/DBAPI.h
        DESTINATION include/DBManager)

# 是否配置Test
if(SG_BUILD_UNIT_TEST)
  add_subdirectory(UnitTest)
endif()
